package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.admin.util.UploadUtil;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelContent;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by 13925 on 2018/10/29.
 */

/**
 * 用户游记管理层
 */
@Controller
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    IStrategyService strategyService;

    @Autowired
    private IRegionService regionService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") StrategyQuery qo, Model model) {
        PageInfo result = strategyService.query(qo);
        model.addAttribute("result", result);
        model.addAttribute("regions", regionService.selectAll());
        return "strategy/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MultipartFile file, Strategy strategy) {
        //如果页面上添加/修改了文件
        if (file != null && file.getSize() > 0) {
            //文件上传
            String coverUrl = UploadUtil.upload(file, UploadUtil.BASE_IMAGE_PATH + "/upload");
            strategy.setCoverUrl(coverUrl);
        }
        strategyService.saveOrUpdate(strategy);
        return "redirect:/strategy/list.do";
    }


}
